import { Entity, Column, ManyToOne, JoinColumn } from "typeorm";
import { Base } from "@/entities.base/base.entity";
import { Order } from "../order.entity";
import { CustomerStoredValueCard } from "../customer-stored-value-card.entity";

@Entity({ comment: '订单储值卡使用记录表', name: 'basis_order_stored_value_usage' })
export class OrderStoredValueUsage extends Base {

    /** 使用金额 */
    @Column({
        comment: '使用金额',
        type: 'decimal',
        precision: 10,
        scale: 2,
    })
    usedAmount: number;

    /** 使用前余额 */
    @Column({
        comment: '使用前余额',
        type: 'decimal',
        precision: 10,
        scale: 2,
    })
    balanceBefore: number;

    /** 使用后余额 */
    @Column({
        comment: '使用后余额',
        type: 'decimal',
        precision: 10,
        scale: 2,
    })
    balanceAfter: number;

    /** 备注 */
    @Column({
        type: 'text',
        comment: '备注',
        nullable: true,
    })
    remark?: string;

    /** 关联的订单ID */
    @Column({
        comment: '订单ID',
        nullable: false,
    })
    orderId: string;

    /** 关联的客户储值卡ID */
    @Column({
        comment: '客户储值卡ID',
        nullable: false,
    })
    customerStoredValueCardId: string;

    /** 关联订单 - 多对一关系 */
    @ManyToOne(() => Order, order => order.storedValueUsages, { onDelete: 'CASCADE' })
    @JoinColumn({ name: 'orderId' })
    order: Order;

    /** 关联客户储值卡 - 多对一关系 */
    @ManyToOne(() => CustomerStoredValueCard, { onDelete: 'CASCADE' })
    @JoinColumn({ name: 'customerStoredValueCardId' })
    customerStoredValueCard: CustomerStoredValueCard;
} 